import onnx

def analyze(onnxfile, **kwargs):
    model = onnx.load(onnxfile)

    dict_sp = {}
    dict_tanh = {}
    dict_mul = {}

    merge_mish = False
    got_mish_node = False

    for node_id, node in enumerate(model.graph.node):
        if node.op_type == 'Mish':
            got_mish_node = True

        if node.op_type == 'Softplus':
            dict_sp['input'] = node.input
            dict_sp['output'] = node.output
            dict_sp['id'] = node_id
            node.op_type = 'Mish'

        if node.op_type == 'Tanh':
            if dict_sp and node.input == dict_sp['output']:
                dict_tanh['input'] = node.input
                dict_tanh['output'] = node.output
                dict_tanh['id'] = node_id
                print('got first pair:', dict_tanh['input'], dict_tanh['output'])
            else:
                print('clear Softplus')
                dict_sp = {}    

        if node.op_type == 'Mul':
            if dict_sp and dict_tanh and node.input[1] == dict_tanh['output'][0] and node.input[0] == dict_sp['input'][0]:
                dict_mul['input'] = node.input
                dict_mul['output'] = node.output
                dict_mul['id'] = node_id

                print('got second pair:', dict_mul['input'], dict_mul['output'])

                merge_mish = True

                dict_sp = {}
                dict_tanh = {}
                dict_mul = {} 
            else:
                print('clear Softplus and Tanh')
                dict_sp = {}
                dict_tanh = {} 

    if got_mish_node == True and merge_mish == False:
        return True

    return False